package com.zpark.servlet_response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @PackageName: com.zpark.servlet_response
 * @ClassName: ServletResponseDemo03
 * @Description:
 * @author: RZS
 * @date: 2023/3/9  17:23
 */
@WebServlet("/sp03.do")
public class ServletResponseDemo03 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 解决响应乱码问题
        // 设置response缓冲区的编码
        response.setCharacterEncoding("UTF-8");
        // 设置浏览器打开文件所采用的编码
        response.setContentType("text/html;charset=UTF-8");

        // 用于获取字符输出流对象。
        PrintWriter writer = response.getWriter();
        writer.println("<html>");
        writer.println("<body>");
        writer.println("<h2>你好，Servlet Response对象</h2>");
        writer.println("</body>");
        writer.println("</html>");

        writer.close();
    }
}
